package com.dzx.permissionmanagersystem.controller;

import com.dzx.permissionmanagersystem.common.ApplicationContextHelper;
import com.dzx.permissionmanagersystem.common.JsonData;
import com.dzx.permissionmanagersystem.dao.SysAclModuleMapper;
import com.dzx.permissionmanagersystem.exception.PermissionException;
import com.dzx.permissionmanagersystem.param.TestVo;
import com.dzx.permissionmanagersystem.util.BeanValidator;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.xml.ws.spi.http.HttpContext;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeSet;
import java.util.concurrent.ConcurrentSkipListSet;

@Controller
@Slf4j
public class TestController {

    @Autowired
    private HttpSession session;

    @GetMapping("/hello")
    @ResponseBody
    public JsonData test(HttpSession session){
       session.setAttribute("user","用户信息");
       return  JsonData.fail("s");
    }

    @GetMapping("/getUser")
    @ResponseBody
    public JsonData test( ){
        String s =  (String) session.getAttribute("user");
        log.info(s);
        return  JsonData.fail("s");
    }


    @GetMapping("/exception")
    public  String toException(){
        return "exception";
    }

    @GetMapping("/world")
    public ModelAndView toHello(HttpServletRequest  request){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("hello");
        return modelAndView;
    }


    @GetMapping("/validate.json")
    @ResponseBody
    public JsonData toHello(TestVo vo,HttpContext context){
       log.info("validate");
       BeanValidator.check(vo);

        SysAclModuleMapper moduleMapper = ApplicationContextHelper.popBean(SysAclModuleMapper.class);

        TreeSet treeSet = new TreeSet();



        return JsonData.success("test validate");
    }



}
